import { reqGetGoodsDetailInfo } from '@/api'

const state = {
  detailInfo: {},
}

const actions = {
  async GetGoodsDetailInfo({ commit }, id) {
    const res = await reqGetGoodsDetailInfo(id)
    if (res.code === 200) {
      commit('SAVE_DETAIL_INFO', res.data)
    } else {
      console.log(res.message)
    }
  },
}

const mutations = {
  SAVE_DETAIL_INFO(state, payload) {
    state.detailInfo = payload
  },
}

const getters = {
  // 面包屑数据
  categoryView(state) {
    return state.detailInfo.categoryView || {}
  },
  // 商品信息
  skuInfo(state) {
    return state.detailInfo.skuInfo || {}
  },
  // 商品售卖属性
  spuSaleAttrList(state) {
    return state.detailInfo.spuSaleAttrList || []
  },
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
